<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "attr_value".
 *
 * @property int $id
 * @property string $name 名称
 * @property int $attr_name_id 属性名id
 * @property-read AttrName $attrName 属性名
 */
class AttrValue extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'attr_value';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['name'], 'required'],
            [['name'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'name' => Yii::t('app', 'Name'),
            'attr_name_id' => Yii::t('app', 'Attr Name ID'),
        ];
    }

    public function getAttrName()
    {
        return $this->hasOne(AttrName::class, ['id' => 'attr_name_id']);
    }

    public function extraFields()
    {
        return array_merge(parent::extraFields(), [
            'attrName'
        ]); // TODO: Change the autogenerated stub
    }
}
